package Dao;

import java.sql.Connection;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import Vao.User;

public class UserDao {
    public int checkId(String account,String password) throws Exception{
        int id=0;
        Connection conn=null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/library";
            String username="root";
            String password1="17876724541";
            conn =DriverManager.getConnection(url,username,password1);

            String sql="select userId from user where account=? and password=?";
            PreparedStatement ps=conn.prepareStatement(sql);
            ps.setString(1, account);
            ps.setString(2, password);
            ResultSet rs=ps.executeQuery();
            while(rs.next()){
                id=rs.getInt(1);
            }
            rs.close();
            ps.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return id;
    }


}
